package com.wolves.career.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wolves.career.entity.AboutUsLeaveWord;
import com.wolves.career.mapper.AboutUsLeaveWordMapper;
import com.wolves.career.service.AboutUsLeaveWordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 麦翔盛
 * @since 2021-10-27
 */
@Service
public class AboutUsLeaveWordServiceImpl extends ServiceImpl<AboutUsLeaveWordMapper, AboutUsLeaveWord> implements AboutUsLeaveWordService {

    @Override
    public QueryWrapper<AboutUsLeaveWord> getMessageQuery(AboutUsLeaveWord message) {
        QueryWrapper<AboutUsLeaveWord> queryWrapper = new QueryWrapper<>();
        //先根据封装类获取需要查询的信息
        String userId = message.getUserId();
        String content = message.getContent();
        String leaveWordId = message.getLeaveWordId();
        Integer leaveWordState = message.getLeaveWordState();
        Date createTime = message.getCreateTime();
        //不允许修改所以没有获取更新时间这个字段
        //TODO 如果后期更改需求才改变这里
        if (!StringUtils.isEmpty(userId)){
            queryWrapper.eq("user_id",userId);
        }
        if (!StringUtils.isEmpty(content)){
            queryWrapper.like("content",content);
        }
        if (!StringUtils.isEmpty(leaveWordId)){
            queryWrapper.eq("leave_word_id",leaveWordId);
        }
        if (!StringUtils.isEmpty(leaveWordState)){
            queryWrapper.eq("leave_word_state",leaveWordState);
        }
        if (!StringUtils.isEmpty(createTime)){
            queryWrapper.gt("create_time",createTime);
        }
        return queryWrapper;

    }
}
